refactor: add ArgumentValidationError to @crawlee/core#3716
Conversation
A shared error class for schema (zod) validation failures. Its `message` is a human-readable sentence naming the offending field and the value it received, while the structured zod `issues` are exposed directly on the error (and the original `ZodError` on `cause`). This is the foundation for migrating Crawlee's argument validation from `ow` to `zod`; the Apify SDK re-exports it for the same purpose.
|
Now I realized we wanted to drop this SDK<->crawlee dependency, but even in that case, we want the same error handling experience (as well as zod instead of ow), so I'd merge this in regarldess. |
Agreed, but maybe we could put this in a package smaller than core? If SDK ends up depending on utils, for instance, nobody will bat an eye... |
|
We might want to take a closer look at this, and maybe even introduce some |
|
Yeah, makes sense. |
Adds a shared
ArgumentValidationError(exported from@crawlee/coreviaerrors.ts) for schema (zod) validation failures.message— a plain, human-readable sentence naming the offending field and the value it received, e.g.Invalid string: must match pattern /^[A-Z]{2}$/ at `countryCode`, got `CZE`. Not a JSON dump.issues— the structured zod issues, exposed directly on the error so consumers can branch on them without digging intocause.cause— the originalZodError, kept for completeness.The constructor takes
(error: ZodError, value: unknown)and formats the message itself (thevalueis walked by each issue'spathto surface the offending value).Why
This is the foundation for migrating Crawlee's argument validation from
owtozod. The Apify SDK has just done the same migration and currently defines this class itself (apify-sdk-js#636) — once this lands and releases, the SDK will re-export it from@crawlee/coreinstead, so the two stay in lockstep.Scope is intentionally just the error class (+ its formatter and a test) — no
owcall sites are migrated here.@crawlee/corealready depends onzod; built in dependency order + lint + the new test all pass.🤖 Generated with Claude Code